/*
*	This file contains all calender-related functions
*/

// populate the 'day' control when user select a month
function populate_days()
{
	var monthControl =  document.getElementById("monthReportForm");
	var yearControl = document.getElementById("yearReportForm");
	var startDayControl = document.getElementById("startDayReportForm");
	var endDayControl = document.getElementById("endDayReportForm");
	var number_of_days = daysInMonth(yearControl.options[yearControl.selectedIndex].value,monthControl.options[monthControl.selectedIndex].value);

	for(i=0;i<31;i++){
		startDayControl.options[i]=null;
		endDayControl.options[i]=null;
	}
	for (var i=0; i < number_of_days ; i++){
		var x= String(i+1);
		startDayControl.options[i] = new Option(x);
		endDayControl.options[i] = new Option(x);
	}
}

function daysInMonth(iYear, iMonth)
{
    return 32 - new Date(iYear, iMonth, 32).getDate();
}

function displayDate()
{
	var now=new Date()

	var hrs=now.getHours()

	var min=now.getMinutes()

	var sec=now.getSeconds()

	var day =now.getDate();

	var ngay=now.getDay();

	var month = now.getMonth()+1;

	var year = now.getFullYear();

	var strDate = "";

	var don="AM"

	if (hrs>=12){ don="PM" }

	if (hrs>12) { hrs-=12 }

	if (hrs==0) { hrs=12 }

	if (hrs<10) { hrs="0"+hrs }

	if (min<10) { min="0"+min }

	if (sec<10) { sec="0"+sec }

	switch(ngay)

	{

	case 0: strDate = "Chu Nhat, ";break;case 1:strDate = "Thu 2, ";break;case 2:strDate = "Thu 3, ";break;case 3:strDate = "Thu 4, ";break;case 4:strDate = "Thu 5, ";break;case 5:strDate = "Thu 6, ";break;case 6:strDate = "Thu 7, ";

	}

	document.getElementById('todaydate').innerHTML= strDate + day+"/"+month+"/"+year + " - " + hrs + ":" + min + ":" + sec + " " + don;

	setTimeout("displayDate()",1000);

}